<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Contracts\Validation\Validator;

class StoreDisclosureRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'code' => 403, // 你想要的状态码
            'msg' => $validator->errors()->all()[0]
        ], 200)); // 同样设置响应码为422
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'title' => 'required',
            'schedule_id' => 'required',
            'region_id' => 'required',
            'type_id' => 'required',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'title.required' => '请输入任务名称',
            'schedule_id.required' => '请选择工序流程',
            'region_id.required' => '请选择区域',
            'type_id.required' => '请选择类型',
        ];
    }
}
